package br.com.agregador.entity;

import java.io.Serializable;
import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.SequenceGenerator;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

@Entity
@SequenceGenerator(name="click_seq", sequenceName="click_seq", allocationSize=1)
public class Click implements Serializable{

	private static final long serialVersionUID = 1L;
	
	@Id
    @GeneratedValue(strategy=GenerationType.SEQUENCE, generator="click_seq")
	private Long id;
	
	@Column(nullable=false,columnDefinition="integer")
	private Integer qtdClick;
	
	@Column(nullable=false)
	@Temporal(TemporalType.DATE)
	private Date dataDia;
	
	@ManyToOne(fetch=FetchType.LAZY, targetEntity=Oferta.class)
	@JoinColumn(name="d",referencedColumnName="id",nullable=false,insertable=true,updatable=true)
	private Oferta oferta;
	
	@ManyToOne(fetch=FetchType.LAZY, targetEntity=CPC.class)
	@JoinColumn(name="cpc_id",referencedColumnName="id",nullable=false,insertable=true,updatable=true)
	private CPC cpc;
	
	public Click(){		
	}

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public Integer getQtdClick() {
		return qtdClick;
	}

	public void setQtdClick(Integer qtdClick) {
		this.qtdClick = qtdClick;
	}

	public Date getDataDia() {
		return dataDia;
	}

	public void setDataDia(Date dataDia) {
		this.dataDia = dataDia;
	}
	
	public Oferta getOferta() {
		return oferta;
	}

	public void setOferta(Oferta oferta) {
		this.oferta = oferta;
	}
	
	public CPC getCpc() {
		return cpc;
	}

	public void setCpc(CPC cpc) {
		this.cpc = cpc;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((id == null) ? 0 : id.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Click other = (Click) obj;
		if (id == null) {
			if (other.id != null)
				return false;
		} else if (!id.equals(other.id))
			return false;
		return true;
	}			
}
